package com.quickcode.example.collections;

import com.google.common.collect.Maps;
import com.quickcode.annotation.Safe;

import java.util.Collections;
import java.util.Map;

/**
 * Created by 张波 on 2019/10/23.
 */
@Safe
public class ImmutableExample1 {

    private static Map<Integer,Integer> map = Maps.newHashMap();

    static {
        map.put(1,2);
        map.put(3,4);
        map.put(5,6);
        //执行过unmodifiable后不允许再进行修改了，下述main方法进行赋值会报异常
        map = Collections.unmodifiableMap(map);
    }

    public static void main(String[] args) {
        map.put(7,8);
        System.out.println(map.get(7));
    }
}
